﻿using Catastrophe.BasePC.UI.MyEnum;
using Catastrophe.BasePC.UI.UIMode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Catastrophe.BasePC.UI.UI
{
    /// <summary>
    /// UcSysUserEdit.xaml 的交互逻辑
    /// </summary>
    public partial class UcSysUserEdit : Window
    {   /// <summary>
        /// 鼠标是否按下
        /// </summary>
        private bool isMouseDown { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public WindowTypeEnum windowType { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public event Action<bool> WindowClose;
        public UcSysUserEditModel mode { get; set; }
        public UcSysUserEdit()
        {
            InitializeComponent();
            this.Closing += UcSysUserEdit_Closing;
            this.Loaded += UcSysUserEdit_Loaded;
            mode = this.DataContext as UcSysUserEditModel;
            mode.FlagChanged += Mode_FlagChanged;
        }

        private void Mode_FlagChanged(bool obj)
        {
            if (obj)
            {
                this.Close();
            }
        }

        private void UcSysUserEdit_Loaded(object sender, RoutedEventArgs e)
        {
            mode.windowType = windowType;
            if (windowType==WindowTypeEnum.Edit)
            {
                mode.SetSelectItem();
                mode.WindowTitleName = "编辑";
            }
            if (windowType==WindowTypeEnum.Add)
            {
                mode.WindowTitleName = "添加";
            }
        }

        private void UcSysUserEdit_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
        {
            WindowClose?.Invoke(true);
        }

        private void Label_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            isMouseDown = true;
        }

        private void Label_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
                if (isMouseDown)
                {
                    DragMove();
                }
            }
        }

        private void Label_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            isMouseDown = false;
        }
        private void btn_close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
